﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using QzEbook.AccessObject;
using System.Collections.Generic;

public partial class admin_module_comments : System.Web.UI.UserControl
{
    private int bookID;
    private StringBuilder sb;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (String.IsNullOrEmpty(Request["Bid"]))
        {
            Response.Write("不能从处部提交数据");
            Response.End();
        }
        bookID = int.Parse(Request["Bid"]);
        bindData();
    }

    private void bindData()
    {
        sb = new StringBuilder();
        Comment comment = new Comment();
        comment.BookId = bookID;
        List<Comment> commentList = comment.selectList();

        sb.AppendLine("<ul id=\"messagepane\">");
        if (commentList.Count == 0)
        {
            sb.AppendLine("<li>暂无评论</li>");
        }
        else
        {
            int i = 0;
            foreach (Comment item in commentList)
            {
                if ((i++ % 2) == 0)
                {
                    sb.AppendLine("<dl>");
                }
                else
                {
                    sb.AppendLine("<dl class='spacing'>");
                }
                sb.AppendFormat("<dt>{0}</dt><dd><textarea>{1}</textarea></dd>", item.UserName, item.Content);
                sb.AppendLine("</dl>");
            }
        }
        sb.AppendLine("</ul>");
    }


    protected override void Render(HtmlTextWriter writer)
    {
        if (sb != null)
        {
            writer.Write(sb.ToString());
        }
        base.Render(writer);
    }
}
